package edu.gdut.thesissys.action.director;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.gdut.thesissys.action.BaseAction;
import edu.gdut.thesissys.service.TeacherService;

/**
 * 增删改teacher
 * 
 * @author gauze
 * 
 */
public class UpdateTeacherAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final Logger log = LoggerFactory
			.getLogger(UpdateTeacherAction.class);
	@Resource(name = "teacherService")
	private TeacherService teacherService;

	private Object result = new Object();// 处理参数后返回的json信息
	// 教师信息
	private String newTeacherId;// 新工号
	private String teacherId; // 工号
	private String name; // 姓名
	private String sex; // 性别
	private String duty; // 职称
	private String phone; // 电话
	private String powerRight; // 权限
	private Integer limitNum; // 限制所带学生数
	private String email; // 邮箱
	private String password; // 密码
	private Integer majorId; // 专业ID

	/**
	 * 保存或更新teacher
	 * 
	 * @return
	 */
	public String saveOrUpdateTeacher() {
		log.info("save or update teacher " + teacherId + ", " + name);
		this.result = teacherService.saveOrUpdateTeahcer(this);
		log.info("save or update teahcher successful and return "
				+ result.toString());
		return SUCCESS;
	}

	/**
	 * 删除teacher
	 * 
	 * @return
	 */
	public String deleteTeacher() {
		log.info("delete teacher " + teacherId);
		this.result = teacherService.deleteTeacher(this.teacherId);
		log.info("delete teacher successful and return " + result.toString());
		return SUCCESS;
	}

	public void validateSaveOrUpdateTeacher() {
		if (newTeacherId == null || teacherId == null || name == null
				|| sex == null || duty == null || phone == null
				|| powerRight == null || limitNum == null || email == null
				|| password == null || majorId == null) {
			this.addActionError("error params");
			log.info("save or update teacher failed because of error params");
		}
	}

	public void validateDeleteTeacher() {
		if (teacherId == null) {
			this.addActionError("error params");
			log.info("delete teacher failed because of error param");
		}
	}

	@JSON(serialize = false)
	public String getNewTeacherId() {
		return newTeacherId;
	}

	public void setNewTeacherId(String newTeacherId) {
		this.newTeacherId = newTeacherId;
	}

	@JSON(serialize = false)
	public String getTeacherId() {
		return teacherId;
	}

	public void setTeacherId(String teacherId) {
		this.teacherId = teacherId;
	}

	@JSON(serialize = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@JSON(serialize = false)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@JSON(serialize = false)
	public String getDuty() {
		return duty;
	}

	public void setDuty(String duty) {
		this.duty = duty;
	}

	@JSON(serialize = false)
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@JSON(serialize = false)
	public String getPowerRight() {
		return powerRight;
	}

	public void setPowerRight(String powerRight) {
		this.powerRight = powerRight;
	}

	@JSON(serialize = false)
	public Integer getLimitNum() {
		return limitNum;
	}

	public void setLimitNum(Integer limitNum) {
		this.limitNum = limitNum;
	}

	@JSON(serialize = false)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@JSON(serialize = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@JSON(serialize = false)
	public Integer getMajorId() {
		return majorId;
	}

	public void setMajorId(Integer majorId) {
		this.majorId = majorId;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public Object getResult() {
		return result;
	}
}
